<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <!-- 引入组件库 -->
        <script type="text/javascript" src="../js/jquery.min.js"></script>
        <script src="../js/vue.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
        <style>
            .avatar-uploader .el-upload {
                border: 1px dashed #d9d9d9;
                border-radius: 6px;
                cursor: pointer;
                position: relative;
                overflow: hidden;
            }
            .avatar-uploader .el-upload:hover {
                border-color: #409EFF;
            }
            .avatar-uploader-icon {
                font-size: 28px;
                color: #8c939d;
                width: 178px;
                height: 178px;
                line-height: 178px;
                text-align: center;
            }
            .avatar {
                width: 178px;
                height: 178px;
                display: block;
            }
            .datatable {
                position: relative;
                box-sizing: border-box;
                -webkit-box-flex: 1;
                width: 100%;
                max-width: 100%;
                font-size: 14px;
                color: rgb(96, 98, 102);
                overflow: hidden;
                flex: 1 1 0%;
            }
            .datatable td, .datatable th {
                padding: 12px 0;
                min-width: 0;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                text-overflow: ellipsis;
                vertical-align: middle;
                position: relative;
                text-align: left;
            }
        </style>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>预约管理<small>预约列表列表</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>预约管理</el-breadcrumb-item>
                    <el-breadcrumb-item>预约列表管理</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div class="filter-container">
                        <el-input placeholder="编码/名称/助记码" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                        <el-button @click="findPage()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                        <el-button type="danger" class="butT" @click="handleDelete()">删除</el-button>
                    </div>


                    <el-table size="small" current-row-key="id" :data="dataList" ref="multipleTable" >
                        <el-table-column type="selection" width="55" >
                        </el-table-column>
                        <el-table-column type="index" align="center" label="序号" width="60"></el-table-column>
                        <el-table-column prop="orderTime" label="预约日期" align="center" width="120">

                        </el-table-column>
                        <el-table-column prop="fileNumber" label="档案号" align="center" width="120"></el-table-column>
                        <el-table-column prop="username" label="姓名" align="center" width="120"></el-table-column>
                        <el-table-column prop="phoneNumber" label="手机号码" align="center" width="150"></el-table-column>
                        <el-table-column prop="orderType" label="预约类型" align="center" width="80"></el-table-column>
                        <el-table-column prop="orderStatus" label="预约状态" align="center" width="80"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" :disabled="scope.row.disabled" @click="enter(scope.row)"  id="enter_1">确认预约</el-button>
                                <el-button size="mini" type="danger" id="cancel_1" @click="cancel(scope.$index, dataList,scope.row)">取消预约</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                        </el-pagination>
                    </div>
                    <!-- 新增标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="新增套餐" :visible.sync="dialogFormVisible">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="基本信息" name="first">
                                        <el-form label-position="right" label-width="100px">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="姓名">
                                                        <el-input v-model="formData.username"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="身份证号">
                                                        <el-input v-model="formData.idCard"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>

                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="出生日期">
                                                        <el-date-picker
                                                                v-model="formData.birthday"
                                                                type="date"
                                                                placeholder="选择日期">
                                                        </el-date-picker>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="手机号">
                                                        <el-input v-model="formData.phoneNumber"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>

                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="适用性别">
                                                        <el-select v-model="formData.sex">
                                                            <el-option label="不限" value="0"></el-option>
                                                            <el-option label="男" value="1"></el-option>
                                                            <el-option label="女" value="2"></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="年龄">
                                                        <el-input v-model="formData.age"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>



                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="婚姻状态">
                                                        <el-select v-model="formData.married">
                                                            <el-option label="不限" value="0"></el-option>
                                                            <el-option label="未婚" value="1"></el-option>
                                                            <el-option label="已婚" value="2"></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="预约时间">
                                                        <el-date-picker
                                                                v-model="formData.orderTime"
                                                                type="date"
                                                                placeholder="选择日期">
                                                        </el-date-picker>
                                                    </el-form-item>
                                                </el-col>

                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                    <el-tab-pane label="套餐信息" name="second">
										<div class="checkScrol">
											<table class="datatable">
												<thead>
												<tr>
													<th>选择</th>
													<th>套餐名称</th>
													<th>适用性别</th>
													<th>项目说明</th>
												</tr>
												</thead>
												<tbody>
												<tr v-for="c in tableData">
													<td>
														<input :id="c.id" v-model="checkgroupIds" type="checkbox" :value="c.id">
													</td>
													<td><label :for="c.id">{{c.name}}</label></td>
													<td><label :for="c.id">{{c.sex == '0' ? '不限' : c.sex == '1' ? '男' : '女'}}</label></td>
													<td><label :for="c.id">{{c.remark}}</label></td>
												</tr>
												</tbody>
											</table>
										</div>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleAdd()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>
                </div>
            </div>
        </div>
    </body>

    <script>
        var vue = new Vue({
            el: '#app',
            data:{
                autoUpload:true,//自动上传
                activeName:'first',//添加/编辑窗口Tab标签名称
                pagination: {//分页相关属性
                    currentPage: 1,
                    pageSize:10,
                    total:100,
                    queryString:null,
                },
                dataList: [{id:1,username:'zhangsan',orderTime:'2020-04-04'},{id:2,username:'lishi',orderTime:'2020-03-04'}],//列表数据
                formData: {},//表单数据
                tableData:[],//添加表单窗口中检查组列表数据
                checkgroupIds:[],//添加表单窗口中检查组复选框对应id
                dialogFormVisible: false,//控制添加窗口显示/隐藏
            },
            created() {
                this.findPage();
            },
            methods: {
                //文件上传成功后的钩子，response为服务端返回的值，file为当前上传的文件封装成的js对象
                handleAvatarSuccess(response, file) {

                },
                //上传图片之前执行
                beforeAvatarUpload(file) {

                },
                //添加
                handleAdd () {
                    //先见到那校验数据
                    var regex=/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
                    if (!regex.test(this.formData.idCard)) {
                        this.$message.error("身份证号格式不对!")
                        return;
                    }

                    //校验手机号
                    var regex=/^[1][3,4,5,7,8,9][0-9]{9}$/;
                    if (!regex.test(this.formData.phoneNumber)){
                        this.$message.error("手机号格式不对!");
                        return;
                    }

                    //校验出生日期
                    if (this.formData.birthday > new Date()){
                        this.$message.error("出生日期不能大于今天!");
                        return;
                    }
                  //发送异步请求保存数据
                    var _this=this;
                    axios.post("/orderList/saveOrderList.do?setmeal_id="+_this.checkgroupIds,_this.formData).then((response)=>{
                        if (response.data.flag){
                            _this.$message({
                                type:"success",
                                message:response.data.message
                            });
                        } else {
                            _this.$message.error(response.data.message);
                        }
                    }).finally(()=>{
                        _this.dialogFormVisible=false;
                        _this.findPage()
                    })
                },
                //分页查询
                findPage() {
                    var _this=this;
                    // 准备分页参数
                    var param={
                        currentPage:_this.pagination.currentPage,
                        pageSize: this.pagination.pageSize,
                        queryString: this.pagination.queryString,
                    };
                axios.post("/orderList/findAll.do",param).then((response)=>{
                    if (response.data!=null){
                        _this.dataList=response.data.rows;
                        _this.pagination.total=response.data.total;
                    } else {
                        _this.$message.error(response.data.message);
                    }
                })
                },
                // 重置表单
                resetForm() {
                    this.formData={};
                    this.activeName='first';
                    this.checkgroupIds=[];
                },
                // 弹出添加窗口
                handleCreate() {
                    //弹出新建对话框，但要先清除对话框的内容
                    this.resetForm();
                    this.dialogFormVisible=true;
                    //还要发送请求查询所有的套餐
                    var _this=this;
                    axios.get("/orderList/findAllSetmeal.do").then((response)=>{
                        if (response.data.flag){
                            _this.tableData=response.data.data;
                        } else {
                            _this.$message.error("获取套餐详情失败!")
                        }
                    })


                },
                //切换页码
                handleCurrentChange(currentPage) {
                    this.pagination.currentPage=currentPage;
                    this.findPage();
                },
                // 前端校验身份证
                fun1(){
                    //console.log(this.formData.idCard)
                    var regex= /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
                },
                enter(rows){
                    // 点击确定 禁用确定按钮
                    rows.disabled=true;

                    // 发送异步请求
                    axios.post("/orderList/sendMessage.do",rows).then((response)=>{
                        if (response.data.flag){
                            this.$message({
                                type:"success",
                                message:response.data.message
                            })
                        } else {
                            this.$message.error(response.data.message)
                        }
                    })
                },
                //取消预约
                cancel(index, rows,row){
                    var _this=this;
                    // 先发送axios 删除数据库中的数据
                    axios.post("/orderList/deleteById.do",row).then((response)=>{
                        if (response.data.flag){
                            //rows.splice(index, 1);
                            _this.$message({
                                type:'success',
                                message:response.data.message
                            });
                            _this.findPage()
                        } else {
                            _this.$message.error(response.data.message)
                        }
                    })

                },
                // 删除用户选中的orderlist 行
                handleDelete(){
                    var _this=this;
                    // 准备一个存放id的数据
                    var array = new Array();
                    // 得到复选框的数据
                    var orderList= _this.$refs.multipleTable.selection;
                    for (var i = 0; i < orderList.length; i++) {
                        array.push(orderList[i].id);
                    }
                    // 发送异步请求删除
                    axios.post("/orderList/deleteByIds.do",array).then((response)=>{
                        if (response.data.flag){
                            _this.$message({
                                type:'success',
                                message:response.data.message
                            });
                            _this.findPage();
                        } else {
                            _this.$message.error(response.data.message)
                        }
                    })
                    
                }
            }

        });

    </script>
</html>
